package com.study.mike.common.exception;

import com.study.mike.common.enums.AbstractExceptionEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 自定义业务异常
 *
 * @author kh
 * @date 2021/7/21
 **/
@EqualsAndHashCode(callSuper = true)
@Data
public class BizException extends RuntimeException {

    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    protected String code;
    /**
     * 错误信息
     */
    protected String msg;

    /**
     * 错误数据
     */
    protected Object data;

    public BizException(String code, String msg,Object data) {
        super(msg);
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public BizException(String code, String msg) {
        super(msg);
        this.code = code;
        this.msg = msg;
    }

    @Deprecated
    public BizException(String code, String msg, Throwable cause) {
        super(msg, cause);
        this.code = code;
        this.msg = msg;
    }

    public BizException(AbstractExceptionEnum exception) {
        super(exception.getMsg());
        this.code = exception.getCode();
        this.msg = exception.getMsg();
    }

//    public BizException(AbstractExceptionEnum exception, Object... params) {
//        super(exception.getMsg());
//        this.code = exception.getCode();
//        this.msg = StrUtil.format(exception.getMsg(), params);
//    }
}
